const userApi = require('./api/userApi')
const uploadApi = require('./api/uploadApi')
const fs = require('fs')
const path = require('path')
var morgan = require('morgan')
var multer = require('multer')
var cookieParser = require('cookie-parser')
const bodyParser = require('body-parser')
const express = require('express')
const app = express()
var accessLog = fs.createWriteStream(path.resolve(__dirname,'../src/log/access.log'))
const upload = multer({dest: './upload_tmp/'})//自动创建
app.get('*', function (req, res, next) {
  console.log(`${req.method}-->请求了-->${req.url}`)
  // res.send('连接成功');
  next()
});

app.use(morgan('combined', {stream : accessLog}))
app.use(bodyParser({uploadDir:'./uploads'}))
app.use(bodyParser.json())
app.use(cookieParser('加密字符串'))

app.use('/api/user', userApi);// /api/user：接口拼接路径
app.use('/api/posts',upload.any(), uploadApi)
// app.use("/static",express.static("../../dist"))


app.use(express.static(path.join(__dirname,'../dist')))
app.listen(3000)
console.log('success listen at port: 3000')